const path = require("path")
module.exports = function(source){
	const PluginTemplate = require('./plugin-template')

	let rsource = "return "+source
	let os = new Function(rsource)()
	let fnArr = []
	for(let fn in PluginTemplate){
		fnArr.push(PluginTemplate[fn].toString())
	}
	let ph = path.resolve(__dirname,'../script')
	let code = `
		import Plugin from '${path.join(ph,"./paint_plugin/plugin")}'
		import {CN,EN,Icon,Cst} from '${path.join(ph,"./config")}'
		import Utils from '${path.join(ph,"./utils")}'
		export default class ${os.name} extends Plugin{
			constructor(...args){
				super(...args)
				let __out_config = args[2]
				this.__config = ${source}
				this.merge(this.__config)
				if(__out_config)
					this.merge(__out_config)
				delete this.__config
				this.actionBtns = {}
				this.createClassName(this.classMap)
				if(this.cssText)
					this.injectStyle(this.cssText,this.cn)
				this.renderAction()
				this.bind()
			}
			${fnArr.join("\n")}
		}
	`
	return code
}

